/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-07-05 10:58:00
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-08-20 17:13:41
 * @FilePath: \passiflora-edulis-sims\src\stores\crossword-store.ts
 * @Description:
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineStore, acceptHMRUpdate } from 'pinia'
import { v1_crossword } from 'src/boot/PuzzleApi'
import type { ICrosswordFeatures } from 'src/interfaces/IAdvancedPuzzle'
import type { v1ICrosswordRes } from 'src/interfaces/Responses/Game'

export const useCrosswordStore = defineStore('crossword', {
  state: (): ICrosswordFeatures => ({
    words: {
      Snowman: 'Man made out of snow with carrot nose',
      Rose: 'A kind of red colored flower, symbol of love',
    },
    legend_type: {
      text: '',
      font: {
        font_name: '',
        font_size: 20,
        font_color: '#000000',
      },
      text_align: 'left',
      vertical_align: 'top',
      offet_x: 0,
      offet_y: 0,
    },
  }),

  getters: {
    words_str(): string {
      const lst: string[] = []
      for (const key in this.words) {
        lst.push(`${key}:${this.words[key]}`)
      }
      return lst.join('\n')
    },
  },

  actions: {
    async v1_crossword(): Promise<v1ICrosswordRes> {
      const words = Object.keys(this.words).map((key) => {
        return key
      })
      const res = (await v1_crossword(words)).data
      if (res.status_code == 200) {
        return res.data
      } else {
        return {
          answers: {},
          puzzle_size: [0, 0],
        }
      }
    },
  },
})

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useCrosswordStore, import.meta.hot))
}
